<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2010 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: theme.php
| Author: design@simplevision.dk
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
/*******************************************************************************

        Theme for PHP-Fusion V7.01
        Theme Name: 4Newspapers
        Description: Very minimal design, to bring out the content on the page.
    
        Version: 1.0
        Tags:  bright, one-columns, fixed-width.
        Modification: instructions are inside of README file.
        
        Author: SimpleVision
        email: design@simplevision.dk
        site: http://simplevision.dk     

        Copyright (c) 2010 SimpleVision.dk
        Licences: AGPLv3     
    
******************************************************************************/



/// Theme general
define("THEME_BULLET", "");
define("RELATIVE_DATE", false);



if (!defined("IN_FUSION")) { die("Access Denied"); }
require_once INCLUDES."theme_functions_include.php";
function get_head_tags(){
}

function render_page($license=false) {
	global $aidlink, $locale, $settings, $main_style,$fusion_page_title;
	
	echo "<div class='wrapper'>
<div id='header'>
  
  <div id='menu'>    <div id='tools'>
<div id='logo'></div>
    <ul id='user-nav'>";
	if(iMEMBER){
		echo "
              <li><a href='".BASEDIR."edit_profile.php'>".$locale['global_120']."</a> </li>
              <li><a href='".BASEDIR."messages.php'>".$locale['global_121']."</a></li>
              ".(iADMIN ? "<li><a href='".ADMIN."index.php".$aidlink."' >".$locale['global_123']."</a></li>" : "")."
              <li><a href='".BASEDIR."setuser.php?logout=yes'>".$locale['global_124']."</a></li>\n";
	}else{
		echo "
              <li><a href='".BASEDIR."login.php'>".$locale['global_104']."</a></li>
              ".($settings['enable_registration'] ? "
              <li><a href='".BASEDIR."register.php'>".$locale['global_107']."</a></li>" : "");
	}
	echo "
    </ul>   
  </div>
    <div id='container'> ".render_menu(showsublinks(""));
	
	echo 		"        
    </div>
  </div>
</div>
<div id='banner'>
    <h1>".$fusion_page_title."</h1>
    <div id='bannerdump'>
    </div>
</div>";

	echo "<div class='content'>
  
  <div id='main'  class='".basename(FUSION_SELF, ".php")."-".preg_replace("/=[0-9]/","",FUSION_QUERY)."' style='width:100%'>
        ".U_CENTER.CONTENT.L_CENTER."
 		</div>
	<div id='footer'>	
	<div class='right'><ul><li>".showcounter()."</li>	
		<li>".sprintf($locale['global_172'], substr((get_microtime() - START_TIME),0,4))."</li></ul></div>
		".(!$license ? "<div>".showcopyright()."<br />Theme <b>4Newspapers</b> created by <a href='http://simplevision.dk/php-fusion/' lang='en' title='php-fusion themes'>simplevision</a> and funded by <a href='http://live-koncerter.dk' title='Koncerter i Danmark' lang='da'>koncerter i danmark</a> 
						</div>" : "").stripslashes($settings['footer'])."
	</div></div></div>
<script type='text/javascript' src='".THEME."js/fusion.js' ></script>
<script type='text/javascript'>
$().ready(function() {  
   $('body').MakeFusion({
   thumbsPerRow:".$settings['thumbs_per_row']."	
   });  
  });
</script>

	";
}

function render_news($subject, $news, $info) {
	global $locale;	
	opentable(isset($_GET['readmore'])?$subject: "","","newsitem");
	echo (isset($_GET['readmore'])? "": "<h2 class='panelcap'><a href='news.php?readmore=".$info['news_id']."'>".$info['news_subject']."</a></h2><span class='newsdate'>".(RELATIVE_DATE ? time_since($info['news_date']):showdate("newsdate",$info['news_date']))."</span>");
	echo (isset($_GET['readmore'])? "<div class='item'><span class='newsdate'>From ".(RELATIVE_DATE ? time_since($info['news_date']):showdate("newsdate",$info['news_date']))."</span><p class='news-article'>".$news."</p></div>": "<div class='item'>".$news."</div>");
	closetable();
}

function render_article($subject, $article, $info) {
	global $locale;	
	opentable(isset($_GET['cat_id'])?$subject: "","","article");
	echo "<div class='item'>".($info['article_breaks'] == "y" ? nl2br($article) : $article)."</div>
	<div class='item-footer'>
		".articleposter($info," &middot;").articleopts($info,"&middot;").itemoptions("A",$info['article_id']).
		"</div>";
	closetable();
}
function opentable($title,$tableID="",$cssID="") {
	global $locale;	
	$fileName=basename(FUSION_SELF, ".php");
	$id =empty($tableID) ? "":$tableID;
	
	
	echo "<div ".(preg_match("/^[0-9]+/",$tableID) || empty($tableID) ?'': 'id="'.$tableID.'"')."  class='panelbody ".(empty($cssID) ? $fileName." ".(isset($_GET['album_id']) ? $fileName." css".array_search($title, $locale):"css"):$cssID)."'>".(!empty($title) ? "<h2 class='panelcap'>$title </h2>" : "");
}

function closetable() {
	echo "</div>";
}

$panel_collapse = false;
function openside($title, $collapse = false, $state = "on") {
	
	static $box_id = 0; $box_id++;
	global $panel_collapse, $p_data; $panel_collapse = $collapse;
	
	if($p_data['panel_filename'] == "css_navigation_panel") $title = "";
	
	opentable(($collapse ? panelbutton($state,$box_id) : "").$title);
	echo ($collapse ? panelstate($state, $box_id) : "");
}

function closeside() {

	global $panel_collapse, $p_data;
	
	echo ($panel_collapse ? "</div>" : "");
	closetable();
}

function render_menu($original) {
	if (strpos( $original,ltrim(FUSION_REQUEST,"/"))) {
		return  replace_menu(ltrim(FUSION_REQUEST,"/"),$original);
	} else {
		return replace_menu(ltrim(FUSION_SELF),$original);
	}	
}
function replace_menu($value,$original) {
	return	preg_replace(
		"^(href='(\.\./)*".(
			preg_match("(forum)",cleanurl($_SERVER['PHP_SELF']))
			? "forum/index.php" :preg_quote($value)
			)."')^i",
		"\\1  class=\"current\"",
		$original
		);	
}



function time_since($original) {
	// array of time period chunks
	$chunks = array(
		array(60 * 60 * 24 * 365 , 'year'),
		array(60 * 60 * 24 * 30 , 'month'),
		array(60 * 60 * 24 * 7, 'week'),
		array(60 * 60 * 24 , 'day'),
		array(60 * 60 , 'hour'),
		array(60 , 'minute'),
		);
	
	$today = time(); /* Current unix time  */
	$since = $today - $original;
	
	if($since > 604800) {
		$print = date("M jS", $original);
		
		if($since > 31536000) {
			$print .= ", " . date("Y", $original);
		}

		return $print;

	}
	
	// $j saves performing the count function each time around the loop
	for ($i = 0, $j = count($chunks); $i < $j; $i++) {
		
		$seconds = $chunks[$i][0];
		$name = $chunks[$i][1];
		
		// finding the biggest chunk (if the chunk fits, break)
		if (($count = floor($since / $seconds)) != 0) {
			// DEBUG print "<!-- It's $name -->\n";
			break;
		}
	}

	$print = ($count == 1) ? '1 '.$name : "$count {$name}s";

	return $print . " ago";

}

?>
